import {
    deleteContent,down
  } from './levelCommissionsRulesServ'
  // import { parse } from 'qs'
  import { message} from 'antd'
  // import moment from 'moment'
  import {isEmpty, isArray, cloneDeep, merge} from 'lodash'
  // import { hashHistory } from 'dva/router'
  // import { getProduct } from './commissionsListServ.js'
  // import { makeAddress,download } from "utils/util"
  import config from 'config/config'
  import $ from 'jquery';
  
  const defultState = {
      biz:{
        queryForm: {}
      },
      submitLoading: false,
      submitFeikongLoading: false,
      backLoading: false,
      loading: false,
      products:[],
      id:"",
     
  }
  
  const tmpModule = {
    state: cloneDeep(defultState),
    subscriptions: {
      setup ({dispatch, history}) {
        history.listen(({ pathname, query }) => {
          if('' + tmpModule.pathname === '' + pathname){
            dispatch({type: 'updateStore', payload: cloneDeep(defultState)})
          }
        })
      },
    },
  
  
    effects: {
      *deleteContent({payload},{put,select,call}){
        // if(yield call(verifyCommissionTokenFun,{})){
          let {id} = yield select(state => state[tmpModule.namespace])
          let params = {
            id: id
          }
          const { success, msg, data } = yield call(deleteContent, {...params})
          let defultState = yield select(state => state[tmpModule.namespace])
          if(success){
            message.success('删除成功')
            defultState.biz.refreshListDatas(true)
          }
        // }
      },
      *down({payload}, {put, call, select}) {
          let {biz,id} = yield select(state => state[tmpModule.namespace])
          let params = {
            id: id,
            ...biz.queryForm 
          }
          const {data, success} = yield call(down,params)
          if (success) {
            var $a = $("<a>");
            $a.attr("href", data.href);
            $a.attr("download", '佣金申请单明细');
            $("body").append($a);
            $a[0].click();
            $a.remove();
            message.success('导出成功,正在为您下载表格')
          }
      },
    },
    // 存入状态机
    reducers: {
      updateStore(preState, action) {
        return Object.assign({}, preState, action.payload)
      },
    }
  }
  
  export default tmpModule
  